// pages/score/score.js
const app = getApp()
var service = require('../../util/service')
var util = require('../../util/util')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperImgs:[],
    comments: [],
    ispj:false,
    value:0,
    prvId:"",
    lodding: false,
    rprId:"",
    loddtext: "加载中……",
    pageSize: 10,
    page: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var prvId = options.id;
    that.setData({
      'prvId': prvId
    })
  },
  slider2change:function(){
    console.log(this.data.prvId);
    wx.navigateTo({
      url: `../scoreComment/scoreComment?id=${this.data.prvId}&rprId=${this.data.rprId}`
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var user = app.userInfo;
    console.log(user);
    //加载大图 scoreImages
    service.AJAX("smc/sys/LookupValueLine/listLookupValueLine.json", { "$valHdsCode": "scoreImages" }, res => {
      let rows = res;
      for (var i = 0; i < rows.length; i++) {
        rows[i].address = service.imgurl + rows[i].valLnsResult;
      }
      that.setData({
        'swiperImgs': rows
      })
    }, err => { }, 'POST')
    //查看本人是否以点评
    service.AJAX(`smc/dim/ScopeRel/listScopeRel.json?$relType=Provider&$relId=${this.data.prvId}&$userId=${user.buyId}`, {}, res => {
      if (res.length > 0) {
        this.setData({
          ispj: true,
          value: res[0].scopeNumber || 0,
          rprId: res[0].rprId
        });
      }
    }, err => { }, 'GET', true)
    //加载所有点评
    //加载点评人信息
    this.setData({
      comments: []
    })
    this.getScopeRels();
    //CREATED_AT
  },
  getScopeRels: function () {
    var that = this;
    that.setData({
      lodding: true,
      loddtext: "加载中……"
    })
    service.AJAX(`smc/dim/ScopeRel/queryScopeRel.json?$relId=${this.data.prvId}`, { page: that.data.page, pageSize: that.data.pageSize}, res => {
      var orgList = res.rows || [];
      var lodd = orgList.length < 10;
      for (var i = 0; i < orgList.length; i++) {
        orgList[i].createdAt = util.getDate(orgList[i].createdAt);
      }
      var data = that.data.comments.concat(orgList);
      that.setData({
        comments: data,
        lodding: lodd,
        loddtext: lodd ? "没有更多数据了" : "加载中……"
      })
    }, err => { }, 'POST')
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  lower: function () {
    this.setData({
      'page': this.data.page + 1
    })
    this.getScopeRels();
  }
})